package com.fy.fyspace;

import com.fy.fyspace.service.hotness.strategy.HotnessStrategyFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * 热度策略测试类
 * 用于验证策略工厂是否正常工作
 */
@Slf4j
@Component
public class HotnessStrategyTest implements CommandLineRunner {
    
    @Autowired
    private HotnessStrategyFactory strategyFactory;
    
    @Override
    public void run(String... args) throws Exception {
        log.info("=== 热度策略测试开始 ===");
        
        try {
            // 1. 检查策略注册
            var strategyNames = strategyFactory.getAllStrategyNames();
            log.info("已注册的策略: {}", strategyNames);
            
            // 2. 测试获取策略
            for (String strategyName : strategyNames) {
                var strategy = strategyFactory.getStrategy(strategyName);
                if (strategy != null) {
                    log.info("策略 {} 获取成功: {}", strategyName, strategy.getStrategyName());
                } else {
                    log.error("策略 {} 获取失败", strategyName);
                }
            }
            
            // 3. 测试默认策略
            var defaultStrategy = strategyFactory.getDefaultStrategy();
            if (defaultStrategy != null) {
                log.info("默认策略获取成功: {}", defaultStrategy.getStrategyName());
            } else {
                log.error("默认策略获取失败");
            }
            
            // 4. 测试策略信息
            for (String strategyName : strategyNames) {
                var strategyInfo = strategyFactory.getStrategyInfo(strategyName);
                if (strategyInfo != null) {
                    log.info("策略信息 - 名称: {}, 描述: {}, 类型: {}, 启用: {}", 
                        strategyInfo.getName(), 
                        strategyInfo.getDescription(), 
                        strategyInfo.getType(), 
                        strategyInfo.isEnabled());
                } else {
                    log.error("策略信息获取失败: {}", strategyName);
                }
            }
            
            log.info("=== 热度策略测试完成 ===");
            
        } catch (Exception e) {
            log.error("热度策略测试失败", e);
        }
    }
} 